package com.javabasic.algorithm.baidu_interview;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/2/22 10:59 上午
 * 富途面试
 * 1. 两个有序数组求交集
 * 2. 访问baidu.com的全过程
 * 3. 检测发广告的小号（内容检测、频率检测、用户信息以及活跃度检测、误检测--申诉流程）
 */
public class Test1 {


    public static void main(String[] args) {

    }
}

//
//import java.util.*;
//
//// 必须定义 `ShowMeBug` 入口类和 `public static void main(String[] args)` 入口方法
//public class ShowMeBug {
//    public static void main(String[] args) {
//        System.out.println("Hello World!");
//    }
//}
//
//
//
//public class Test2 {
//
//    public static void main(String[] args) {
//        ConcurrentHashMap<Long, List<Condition> > timeToConditionMap = new ConcurrentHashMap<>(16);
//        Clock clock = new Clock(timeToConditionMap);
//        Thread timeThread = new Thread(clock, "时钟线程");
//        timeThread.start();
//        long currentTimeMillis = System.currentTimeMillis();
//
//        System.out.println("当前时间：" + currentTimeMillis);
//        Worker workerA = new Worker(currentTimeMillis + 1000 * 30, timeToConditionMap);
//        Worker workerB = new Worker(currentTimeMillis + 1000 * 40, timeToConditionMap);
//
//        Thread workerAThread = new Thread(workerA, "A工作线程");
//        Thread workerBThread = new Thread(workerB, "B工作线程");
//
//        workerAThread.start();
//        workerBThread.start();
//    }
//}
//
//class Clock implements Runnable {
//    private ConcurrentHashMap<Long, List<Condition> > timeToConditionMap;
//    public Clock(ConcurrentHashMap<Long, List<Condition> > timeToConditionMap) {
//        this.timeToConditionMap = timeToConditionMap;
//    }
//
//    @Override
//    public void run() {
//        while (true) {
//            if (CollectionUtil.isEmpty(this.timeToConditionMap)) {
//                try {
//                    Thread.sleep(2);
//                } catch (InterruptedException e) {
//                    System.out.println(e.getCause() + e.getMessage());
//                    Thread.currentThread().interrupt();
//                } finally {
//                    continue;
//                }
//            }
//            long currentTimeMillis = System.currentTimeMillis();
//
//            for (Map.Entry<Long, List<Condition>> entry : this.timeToConditionMap.entrySet()) {
//
//                if (entry.getKey() < currentTimeMillis) {
//                    for (Condition condition : entry.getValue()) {
//                        condition.signalAll();
//                    }
//                }
//            }
//            try {
//                Thread.sleep(1);
//            } catch (InterruptedException e) {
//                System.out.println(e.getCause() + e.getMessage());
//                Thread.currentThread().interrupt();
//            }
//        }
//    }
//}
//
//
//class Worker implements Runnable {
//
//    private ReentrantLock lock;
//    /**
//     * 截止时间戳
//     */
//    private long waitTime;
//    private Condition condition;
//    private ConcurrentHashMap<Long, List<Condition>> timeToConditionMap;
//
//    public Worker(long waitTime, ConcurrentHashMap<Long, List<Condition>> timeToConditionMap) {
//        this.lock = new ReentrantLock();
//        this.waitTime = waitTime;
//        this.timeToConditionMap = timeToConditionMap;
//        this.condition = lock.newCondition();
//        List<Condition> conditions = this.timeToConditionMap.getOrDefault(this.waitTime, new ArrayList<>());
//        conditions.add(this.condition);
//        this.timeToConditionMap.put(this.waitTime,conditions);
//    }
//
//    @Override
//    public void run() {
//        lock.lock();
//        try {
//            condition.await();
//            System.out.println("================worker==============" + Thread.currentThread().getName());
//        } catch (InterruptedException e) {
//            Thread.currentThread().interrupt();
//        } finally {
//            lock.unlock();
//        }
//    }
//}